/* eslint-disable unicorn/prevent-abbreviations */
import type {IRouteConfig, RootStackParamList} from './typing';

import {NavigationContainer} from '@react-navigation/native';
import {
  CardStyleInterpolators,
  createStackNavigator,
  HeaderStyleInterpolators,
  TransitionPresets,
} from '@react-navigation/stack';
import {Platform} from 'react-native';

import Login from '@/screens/auth/login/index';
import ResetPassword from '@/screens/auth/login/reset-pwd';
import SmsLogin from '@/screens/auth/login/sms-login';
import Appearance from '@/screens/user-center/appearance';
import Language from '@/screens/user-center/language';
import PrivacyPolicy from '@/screens/user-center/privacy-policy';
import Settings from '@/screens/user-center/sys-settings';

import BottomTab from './bottom-tab';
import { defaultStackRouteOptions } from './config';
import {navigationRef} from './root-navigation';

export type {RootStackParamList, RootStackScreenProps} from './typing';

const Stack = createStackNavigator<RootStackParamList>();

function Router() {

  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const routes: IRouteConfig<any>[] = [
    {
      component: Settings,
      name: 'Settings',
      options: {
        headerTitleAlign: 'left',
        headerTitleStyle: {
          fontSize: 18,
          fontWeight: 'normal',
        },
        title: '设置',
      },
    },
    {
      component: Appearance,
      name: 'Appearance',
      options: {
        headerTitleStyle: {
          fontSize: 18,
          fontWeight: 'normal',
        },
        title: '外观',
      },
    },
    {
      component: Language,
      name: 'Language',
      options: {
        headerTitleStyle: {
          fontSize: 18,
          fontWeight: 'normal',
        },
        title: '语言',
      },
    },
    {
      component: PrivacyPolicy,
      name: 'PrivacyPolicy',
      options: {
        headerTitleStyle: {
          fontSize: 18,
          fontWeight: 'normal',
        },
        title: '隐私政策',
      },
    },
    {
      component: Login,
      name: 'LOGIN',
      options: {
        cardStyleInterpolator: CardStyleInterpolators.forVerticalIOS,
        headerShown: false,
        title: '登录',
      },
    },
    {
      component: SmsLogin,
      name: 'SMS_LOGIN',
      options: {
        cardStyleInterpolator: CardStyleInterpolators.forVerticalIOS,
        headerShown: false,
        title: '短信登录',
      },
    },
    {
      component: ResetPassword,
      name: 'RESET_PWD',
      options: {
        cardStyleInterpolator: CardStyleInterpolators.forVerticalIOS,
        headerShown: false,
        title: '重置密码',
      },
    },
  ];

  return (
    <NavigationContainer ref={navigationRef}>
      <Stack.Navigator
        screenOptions={{
          gestureEnabled: true,
          headerStyle: {
            elevation: 0, // Android
            shadowOpacity: 0, // iOS
          },
          headerTitleStyle: {
            fontSize: 18,
            fontWeight: 'bold',
          },
          headerTransparent: Platform.OS === 'ios' ? true : false,
          ...TransitionPresets.SlideFromRightIOS,
          headerStyleInterpolator: HeaderStyleInterpolators.forUIKit,
        }}>
        <Stack.Screen
          component={BottomTab}
          name="HOME"
        />
        {routes.map(route => (
          // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
          <Stack.Screen component={route.component} key={route.name} name={route.name} options={{
            ...defaultStackRouteOptions, ...route.options}} />
        ))}
      </Stack.Navigator>
    </NavigationContainer>
  );
}

export default Router;
